package com.bnyy.medicalHousekeeper.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.SpanUtils;
import com.bnyy.medicalHousekeeper.bean.IndexStats;
import com.bnyy.common.adapter.BaseNormalListAdapter;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2022/9/8
 **/
public class IndexStatsAdapter extends BaseNormalListAdapter<IndexStats.StatsSubject, IndexStatsAdapter.ViewHolder> {

    private int dp12;
    private int itemWidth;

    public IndexStatsAdapter(Context context) {
        super(context);
        dp12 = SizeUtils.dp2px(12);
        itemWidth = ScreenUtils.getScreenWidth() - (dp12 * 4) / 3;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        TextView tv = new TextView(mContext);
        tv.setGravity(Gravity.CENTER_HORIZONTAL);
        tv.setPadding(dp12, dp12, dp12, dp12);
        GradientDrawable bg = new GradientDrawable();
        bg.setCornerRadius(10);
        tv.setBackground(bg);

        return new ViewHolder(tv);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);

        IndexStats.StatsSubject statsSubject = getData(position);

        SpanUtils.with(holder.tv)
                .append(statsSubject.getValue()).setFontSize(18,true).setBold().setForegroundColor(Color.parseColor(statsSubject.getValue_color()))
                .appendLine()
                .append(statsSubject.getContent()).setFontSize(14, true).setForegroundColor(Color.parseColor(statsSubject.getFont_color()))
                .create();

        GradientDrawable bg = (GradientDrawable) holder.tv.getBackground();
        bg.setColor(Color.parseColor(statsSubject.getBackground_color()));
    }

    public static class ViewHolder extends BaseNormalListAdapter.ViewHolder {
        TextView tv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = (TextView) itemView;
        }
    }
}























